<?php include_once('header.php');?>
	<div class="main-content">
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			<ul class="breadcrumb">
				<li>
					<i class="icon-home home-icon"></i>
					报价管理
				</li>
				<li>
					报价申请列表
				</li>
			</ul>
		</div>
		<div class="page-content">
			<div class="page-header">
				<h1 class="blue"><i class="icon-edit"></i> 添加报价信息</h1>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<form class="form-horizontal" enctype="multipart/form-data" role="form" method="post" action="/www/quote/add"  onsubmit="return check()">
						<input type="hidden" class="form-control" id="id" name="id" value="<?php echo $data['id'];?>">
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">车主名:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" readonly="readonly" value="<?php echo $data['vehicle_owner'];?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">联系方式:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" readonly="readonly" value="<?php echo $data['phone'];?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">车型号:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" readonly="readonly" value="<?php echo $data['vehicle_model'];?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">车牌号:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" readonly="readonly" value="<?php echo $data['car_num'];?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">发动机:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" readonly="readonly" value="<?php echo $data['engine'];?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">车架号:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" readonly="readonly" value="<?php echo $data['frame_num'];?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">上季度保险公司:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" readonly="readonly" value="<?php echo $data['company_name'];?>">								
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">此单优惠额:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" name="coupon" id="coupon" value="">								
							</div>
						</div>
						<?php 
							foreach($company_list as $key => $value) {
						?>
								<div class="form-group cp_offer">
									<label for="title" class="col-sm-1 control-label"><?php echo $value['company_name'];?>:</label>
									<div class="col-sm-6">					 	
										<input type="hidden" class="form-control" name="quote_data[company_id][<?php echo $key;?>]" value="<?php echo $value['id'];?>">
										<?php foreach($insurance_list as $k => $v) {
											$text = "&nbsp;";
											if(($k + 1)%2 == 0 && ($k + 1) < count($insurance_list)) {
												$text = "<br/><br/>";
											}
										?>
											<span style="width:150px;display: inline-block;"><?php echo $v['name'];?>(<?php echo $v['user_sum'];?>):</span><input type="hidden" class="form-control" name="quote_data[insurance_id][<?php echo $key;?>][]" value="<?php echo $v['id'];?>">
											<input type="text" class="item_offer" name="quote_data[sum_id][<?php echo $key;?>][]" value=""><?php echo $text;?>
										<?php }?>
											小计：<span class="res_offer"></span>元
											<br/>摘要:<textarea class="form-control" rows="2" name="quote_data[remark][<?php echo $key;?>]"></textarea>																											
									</div>
								</div>							
						<?php								
							}
						?>
						
					 	<div class="form-group">
					   		<div class="col-sm-offset-1 col-sm-10">
								<button type="submit" id="submit" name="save" class="btn btn-primary">确定</button>
								<button type="submit" id="submit" name="next" class="btn btn-primary">确定并报价下一个</button>
								<button type="submit" id="cancel" class="btn btn-primary">取消</button>
							</div>
					  	</div>
					</form>	
				</div>
			</div>					
		</div>													
	</div>
<?php include_once('content.php');?>
	<link href="/public_source/www/assets/css/ace.min.css" rel="stylesheet" />	
	<link href="/public_source/www/assets/css/jquery.tag-editor.css" rel="stylesheet"/>
    <script src="/public_source/www/assets/js/bootbox.min.js"></script>  
	<script src="/public_source/www/assets/js/jquery.tag-editor.min.js"></script>
	<script src="/public_source/www/js/areas.js"></script>
<?php include_once('footer.php');?>	
<script type="text/javascript">
	$(document).ready(function(){
		$("#cancel").click(function() {
			window.location.replace('/www/quote/quote_list');
			return false;
		});

		//初始化小计
		$(".cp_offer").each(function(index,item){
			//初始化小计
			var item_offer = $(this).find(".item_offer");
			var res_offer = $(this).find(".res_offer");
			var sum = 0;
			item_offer.each(function(k,v){
				var price = parseInt($(this).val());
				if( !isNaN( price ) ){
					sum += price; 
				}	
			});
			res_offer.html(sum);
			
			//绑定键盘事件
			item_offer.bind("keyup",function(){
				//if( isNaN( parseInt( $(this).val() ) ) ){ alert("报价请填写数字"); }
				var sum = 0;
				item_offer.each(function(k,v){
					var price = parseInt($(this).val());
					if( !isNaN( price ) ){
						sum += price; 
					}	
				});
				res_offer.html(sum);
			});//绑定键盘事件end
		});

	});

	function check() {
	   var coupon = document.getElementById("coupon").value;
	   if(coupon ==  null || coupon == '' || coupon < 0) {
	        alert("优惠额度有误");
	        return false;
	   }
	   return true;
	}
			
</script>	
<style>
	.control-label {
		width:140px;
	}
</style>	